//
//  ComperesListViewController.m
//  RainbowFM
//
//  Created by Kratos on 14/12/11.
//  Copyright (c) 2014年 RB. All rights reserved.
//

#import "ComperesListViewController.h"
#import "CompereDetailsViewController.h"

#import "ComperesListTableViewCell.h"

#import "CompereModel.h"

@interface ComperesListViewController ()
@property (nonatomic , strong) NSMutableArray *comperesList;//主持人列表
@end

@implementation ComperesListViewController

-(void)awakeFromNib
{
    _comperesList= [NSMutableArray array];

}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    typeof(self) self_ = self;
    [[CompereModel sharedModel]fetchComperesListWithAnchorType:AnchorTypeAll PageSize:40 currentPage:0 result:^(NSArray *compereList, NSString *msg) {
        [self_.comperesList removeAllObjects];
        [self_.comperesList addObjectsFromArray:compereList];
        [self_.tableView reloadData];
    }];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


#pragma mark - table datasource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [_comperesList count];
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    ComperesListTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ComperesListTableViewCell"];
    
    if (!cell) {
        NSArray * nibObjects = [[NSBundle mainBundle] loadNibNamed:@"ComperesListTableViewCell" owner:nil options:nil];
        for (id obj in nibObjects){
            if ([obj isKindOfClass:[ComperesListTableViewCell class]]){
                cell = obj;
                break;
            } 
        }
        
    }
    
    CompereItem *item = _comperesList[indexPath.row];
    
    [cell updateContents:item];
    
    return cell;

}




#pragma mark - table delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
//    [self performSegueWithIdentifier:@"compereSegue" sender:[tableView cellForRowAtIndexPath:indexPath]];
    CompereItem *item = _comperesList[indexPath.row];
    NSString *title = item.anchorName;
    
    CompereDetailsViewController *compereDetailsViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"CompereDetailsViewController"];
    compereDetailsViewController.anchorid = item.anchorId;
    [compereDetailsViewController setTitle:title];
    self.navigationController.navigationBar.opaque = YES;
    [self.navigationController pushViewController:compereDetailsViewController animated:YES];
}

@end
